<template>
	<view>
		<view class="header">
			<text>我的</text>
		</view>
		<view class="body">
			<view class="body_top" @tap="toMyMessage">
				<view class="headImg" @tap.stop="toMyDetails">
					<image class="avatar" :src="myInfo.avatar" mode=""></image>
					<!-- <image class="avatar" src="https:www.curiousmore.com/9108/pic/0a18ae31-9dd8-4195-b24e-2eb2b432010f.jpeg" mode=""></image> -->
					<image class="country" v-if="myInfo.national_flag!=''" :src="myInfo.national_flag" mode=""></image>
					
				</view>
				<view class="body_top_mid">
					<view class="nickname">
						<text>{{myInfo.nick_name}}</text>
						<image v-if="myInfo.member_level==1" class="marginLeft" src="../../../static/wode/huiyuan.png" mode=""></image>
						<image v-else-if="myInfo.member_level==2" class="marginLeft" src="../../../static/wode/baijinhuiyuan.png" mode=""></image>
						<image v-else-if="myInfo.member_level==3" class="marginLeft" src="../../../static/wode/zuanshihuiyuan.png" mode=""></image>
						<image v-else class="marginLeft" src="../../../static/wode/huiyuan2.png" mode=""></image>
					</view>
					<view class="place">
						<!-- <text class="idNumber">ID57575</text> -->
						<text v-if="myInfo.city==''">未知</text>
						<text v-else>{{myInfo.country}}·{{myInfo.city}}</text>
					</view>
				</view>
				<view class="body_top_left" @tap="toMyMessage">
					<image src="../../../static/wode/bianji.png" mode=""></image>
					编辑
				</view>
			</view>
			<view class="body2">
				<view class="body_item item_border" @tap="toMyPic">
					<image src="../../../static/wode/xiangce.png" mode=""></image>
					<text>我的相册</text>
				</view>
				<view class="body_item" @tap="toMyDynamics">
					<image src="../../../static/wode/dongtai.png" mode=""></image>
					<text>我的动态</text>
				</view>
			</view>
			<view class="body2">
				<view class="body_item item_border" @tap="toMyMoney">
					<image src="../../../static/wode/zhuanmaobi.png" mode=""></image>
					<text>我的猫币</text>
				</view>
				<view class="body_item item_border" @tap="toGiftCenter">
					<image src="../../../static/wode/liwuzhongxin.png" mode=""></image>
					<text>礼物中心</text>
				</view>
				<!-- <view class="body_item" @tap="toVip">
					<image src="../../../static/wode/huiyuanzhongxin.png" mode=""></image>
					<text>会员中心</text>
				</view> -->
			</view>
			<view class="body_item item_margin" @tap="toProve">
				<image src="../../../static/wode/renzheng.png" mode=""></image>
				<text>认证管理</text>
			</view>
			<view class="body2">

				<view class="body_item item_border" @tap="toHelpCenter" v-if="Ishelp">
					<!-- v-if="masterStatus==2" -->
					<image src="../../../static/wode/ruzhu.png" mode=""></image>
					<text>教学中心</text>
				</view>
				<view class="body_item item_border" @tap="toHelp" v-else>
					<image src="../../../static/wode/ruzhu.png" mode=""></image>
					<text>入驻助学师</text>
				</view>
				<view class="body_item" @tap="toLearn">
					<image src="../../../static/wode/xuexi.png" mode=""></image>
					<text>学习中心</text>
				</view>
			</view>
			<!-- <view class="body_item item_margin" @tap="tohowUse">
				<image src="../../../static/wode/zhinan.png" mode=""></image>
				<text>使用指南</text>
			</view> -->
			<view class="body_item item_margin item_margin2" @tap="toSet">
				<image src="../../../static/wode/shezhi.png" mode=""></image>
				<text>设置</text>
			</view>
			<!-- <view class="body_item item_margin item_margin2" @tap="toCon">
				<image src="../../../static/wode/shezhi.png" mode=""></image>
				<text>我的客服</text>
			</view> -->
		</view>
		<image class="qiandaoMao" src="http://img.curiousmore.com/tmp/wx2f4eaeb7b745ba4e.o6zAJs2bel8UMMafp-gtnT7OfHzo.Rcpfbqj7w2Iw82c7f587bcc1c5733579b50b4ef2da9e.png"
		 mode="" @tap="togetMoney"></image>
		<!-- <view class="" @tap="tolog">
			登录
		</view> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				myInfo: uni.getStorageSync('user_info'),
				user_id: uni.getStorageSync('user_id'),
				masterStatus: '',
				type: '',
				level: '',
				Ishelp:'',
			};
		},
		onShow() {
			if (uni.getStorageSync('user_info') != '' || uni.getStorageSync('user_id')) {
				this.myInfo = uni.getStorageSync('user_info')
				this.Ishelp = this.myInfo.is_help
				console.log(this.myInfo)
			} else {

				uni.showModal({
					title: '提示',
					content: '许多功能需要登录才能使用，要前往登陆吗',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
							uni.navigateTo({
								url: "/pages/Other/login/login"
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				})
			}
			if (uni.getStorageSync('masterStatus') == 2) {
				this.masterStatus = uni.getStorageSync('masterStatus')
			} else {
				this.getMasterStatus()
			}

		},
		onLoad() {
			if (uni.getStorageSync('masterStatus') == 2) {
				this.masterStatus = uni.getStorageSync('masterStatus')
			} else {
				this.getMasterStatus()
			}
		},
		// 		onBackPress() {
		// 			if (this.showMask) {
		// 				this.showMask = false;
		// 				return true;
		// 			} else {
		// 				uni.showModal({
		// 					title: '提示',
		// 					content: '是否退出应用？',
		// 					success: function(res) {
		// 						if (res.confirm) {
		// 							// 退出当前应用，改方法只在App中生效  
		// 							plus.runtime.quit();
		// 						} else if (res.cancel) {
		// 							console.log('用户点击取消');
		// 						}
		// 					}
		// 				});
		// 				return true
		// 			}
		// 		},
		methed() {
			this.myInfo = uni.getStorageSync('user_info')
		},
		methods: {
			toMyMessage() {
				uni.navigateTo({
					url: "/pages/My/myMessage/myMessage"
				})
			},
			toSet() {
				uni.navigateTo({
					url: "/pages/My/set/set"
				})
			},
			toMyDetails() {
				// console.log(11111111)
				uni.navigateTo({
					url: "/pages/My/myDetails/myDetails?user_id=" + this.user_id
				})
			},
			selectMyInfo() {
				var me = this;
				var data = {
					id: uni.getStorageSync('user_id')
				}
				this.myAjaxNew({
					model: 'user',
					controllerName: 'userInfo',
					actionName: 'findById',
					data: data,
					successBack: function(res) {
						console.log(res.data.data)
						me.myInfo = res.data.data
					}
				})
			},
			toMyPic() { //我的相册
				uni.navigateTo({
					url: '/pages/My/myPic/myPic'
				})
			},
			toMyDynamics() { //我的动态
				uni.navigateTo({
					url: '/pages/My/myDynamics/myDynamics?type=dongtai'
				})
			},
			tohowUse() {
				uni.navigateTo({
					url: '/pages/My/howUse/howUse'
				})
			},
			toVip() { //会员中心
				uni.navigateTo({
					url: '/pages/My/vipCenter/vipCenter'
				})
			},
			toMyMoney() { //财富中心
				uni.navigateTo({
					url: '/pages/My/myMoney/myMoney'
				})
			},
			toGiftCenter() {
				uni.navigateTo({
					url: '/pages/My/giftCenter/giftCenter'
				})
			},
			togetMoney() { //赚猫币
				uni.navigateTo({
					url: '/pages/My/getMoney/getMoney'
				})
			},
			toProve() { //认证中心
				uni.navigateTo({
					url: '/pages/My/prove/prove'
				})
			},
			toCon(){
				uni.navigateTo({
					url: '/pages/Other/contact/contact'
				})
			},
			toHelp() {
				
				if (this.Ishelp) {
					uni.navigateTo({
						url: '/pages/My/helpProve/helpProve?type=' + this.type + '&level=' + this.level
					})
				} else {
					uni.navigateTo({
						url: '/pages/My/helpStudy/helpStudy'
					})
				}

			},
			getMasterStatus() {
				var me = this
				var data = {
					user_id: uni.getStorageSync('user_id')
				}
				this.myAjaxNew({
					model: 'user',
					controllerName: 'masterInfo',
					actionName: 'queryListPage',
					data: data,
					successBack: function(res) {
						console.log(res, '助学师状态')
						if (res.data.data.length != 0) {
							for (var i = 0; i < res.data.data.length; i++) {
								if (res.data.data[i].status == 2) {
									me.masterStatus = 2;
									uni.setStorageSync('masterStatus', me.masterStatus)
								}
							}
							me.type = res.data.data[0].type
							me.level = res.data.data[0].grade
							console.log(me.type, me.level)
							if (me.type == 'major') {
								me.type = '专业助学师'
							} else if (me.type == 'cross_border') {
								me.type = '跨境助学师'
							} else if (me.type == 'mother_tongue') {
								me.type = '母语助学师'
							} else if (me.type == 'private_education') {
								me.type = '私教'
							}
						}

					},
				})
			},
			toHelpCenter() {
				console.log(this.masterStatus)
				if (this.Ishelp) {
					uni.navigateTo({
						url: '/pages/My/helpCenter/helpCenter'
					})
				} else {
					uni.showModal({
						title: '提示',
						content: '您还不是助学师，要前往入驻吗',
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
								uni.navigateTo({
									url: '/pages/My/helpStudy/helpStudy'
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					})
				}

			},
			toLearn() {
				uni.navigateTo({
					url: '/pages/My/learnCenter/learnCenter'
				})
			}
		}
	}
</script>

<style scoped>
	.header {
		background: #FFFFFF;
		height: 162upx;
		text-align: center;
		position: fixed;
		top: 0upx;
		width: 100%;
		z-index: 9999;
	}

	.header text {
		position: relative;
		top: 90upx;
	}

	.body {
		padding-top: 162upx;
	}

	.body_top {
		background: #FFFFFF;
		padding: 20upx 24upx;
		display: flex;
		margin-top: 20upx;
		position: relative;
	}

	.headImg {
		position: relative;
		margin-right: 28upx;
	}

	.avatar {
		width: 128upx;
		height: 128upx;
		border-radius: 50%;
		overflow: hidden;
	}

	.country {
		width: 36upx;
		height: 36upx;
		z-index: 10;
		position: absolute;
		left: 0;
		bottom: 10upx;
	}

	.body_top_mid image {
		width: 30upx;
		height: 30upx;
	}

	.body_top_left image {
		width: 25upx;
		height: 29upx;
	}

	.nickname {
		font-size: 32upx;
		color: #333333;
		padding-top: 10upx;
		margin-bottom: 40upx;
	}

	.marginLeft {
		margin-left: 10upx;
	}

	.place {
		font-size: 24upx;
		color: #999999;
	}

	.idNumber {
		margin-right: 40upx;
	}

	.body_top_left {
		color: #999999;
		font-size: 28upx;
		position: absolute;
		right: 24upx;
		top: 30upx;
	}

	.body_item {
		background: #ffffff;
		padding: 22upx 24upx;
		display: flex;
		align-items: center;
		font-size: 32upx;
		color: #333333;
	}

	.item_margin {
		margin-top: 20upx;
	}

	/* .item_margin2 {
		margin-bottom: 118upx;
	} */

	.item_border {
		border-bottom: 1upx solid #E6E6E6;
	}

	.body_item image {
		width: 44upx;
		height: 44upx;
		margin-right: 20upx;
	}

	.body2 {
		background: #ffffff;
		margin-top: 20upx;
	}

	.qiandaoMao {
		width: 115upx;
		height: 140upx;
		position: fixed;
		bottom: 250upx;
		right: 30upx;
	}
</style>
